// Copyright 2017 Baidu Inc. All Rights Reserved.
// Author: Su Hao (suhao@baidu.com)
//
// Description: The random adapter.

#include "baidu_ca_random.h"
#include <time.h>
#include "baidu_ca_internal.h"

BCA_LOC_IMPL bca_random_f s_bca_random = NULL;

BCA_EXT_IMPL void baidu_ca_random_init(bca_random_f f_random) {
    s_bca_random = f_random;
}

BCA_INT_IMPL bca_s32_t bca_random() {
    bca_s32_t rs = 0;

    if (s_bca_random) {
        rs = s_bca_random();
    } else {
        srand(time(NULL));
        rs = rand();
    }

    return rs;
}
